package com.example.service;

import com.example.entity.Message;
import com.example.mapper.MessageMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MessageService {
    @Resource
    MessageMapper messagemapper;

    public List<Message> selectAll(Message message) {
        return messagemapper.selectAll(message);
    }

    public void add(Message message) {
        messagemapper.insert(message);
    }

    public void deleteById(Integer id) {
        messagemapper.deleteById(id);
    }

    public void deleteBatch(List<Integer> ids) {
        for (Integer id : ids) {
            this.deleteById(id);
        }
    }

    public void updateById(Message message) {
        messagemapper.updateById(message);
    }

    public PageInfo<Message> selectPage(Message message, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Message> list = messagemapper.selectAll(message);
        return PageInfo.of(list);
    }

    public Message selectById(Integer id) {
        return messagemapper.selectById(id);
    }
}
